<?php
namespace Admin\Controller;
use Think\Controller;
class SysController extends CommonController {
	public function __construct(){
        parent::__construct();
        $this->config = M('config');
    }
	/*
    title : 系统配置
    time : 2018-05-08 15:48
    username : 安林
     */
    public function sys_config()
    {
        $data = $this->config->select();
        $this->data = $data;
        $this->display();
    }
    /*
    title : 添加系统配置
    time : 2018-05-010 11:40
    username : 安林
     */
    public function Sys_config_add()
    {
        if (IS_AJAX) {
            $arr = I('post.data');
            $value1 = str_replace("&quot;","'",$arr['value1']);
            $value1 = str_replace('&lt;',"<",$value1);
            $value1 = str_replace('&gt;',">",$value1);
            $value1 = str_replace('&amp;',"&",$value1);
            $value2 = str_replace("&quot;","'",$arr['value2']);
            $value2 = str_replace('&lt;',"<",$value2);
            $value2 = str_replace('&gt;',">",$value2);
            $value2 = str_replace('&amp;',"&",$value2);
            $value3 = str_replace("&quot;","'",$arr['value3']);
            $value3 = str_replace('&lt;',"<",$value3);
            $value3 = str_replace('&gt;',">",$value3);
            $value3 = str_replace('&amp;',"&",$value3);
            $arr['value1'] = $value1;
            $arr['value2'] = $value2;
            $arr['value3'] = $value3;
            if ($arr['name']) {
                $list = $this->config->where(array('name'=>$arr['name']))->find();
                if ($list) {
                    $data = [
                        'msg'   =>  '配置已存在！',
                        'res'   =>  201
                    ];
                    $this->ajaxReturn($data,'JSON');
                }
                $res = $this->config->add($arr);
                if ($res) {
                    $data = [
                        'msg'   =>  '添加成功！',
                        'res'   =>  200
                    ];
                }else{
                    $data = [
                        'msg'   =>  '添加失败！',
                        'res'   =>  400
                    ];
                }
                $this->ajaxReturn($data,'JSON');
            }else{
                $data = [
                    'msg'   =>  '请完整填写好配置信息！',
                    'res'   =>  402
                ];
                $this->ajaxReturn($data,'JSON');
            }
        }
        $this->display();
    }
    public function Sys_config_edit()
    {
        $id = I('get.id');
        $data =  $this->config->where(array('id'=>$id))->find();
        $this->data = $data;
        $this->display();
    }
}